<template>
  <div class="login-container">
    <!-- 左侧图片 -->
    <div class="login-left">
      <img  class="aaa" src="../assets/imgs/login.jpg" alt="" />
    </div>
    <div class="login-box">
      <!-- 头像 -->
      <div class="avator-box">
        <img src="../assets/imgs/login_logo.png" alt="" />
      </div>
      <!-- 标题 -->
      <div class="title">欢迎来到登录界面</div>
      <!-- 表单 -->
      <el-form
        ref="ruleForm"
        class="login-form"
        :model="ruleForm"
        :rules="rules"
      >
        <el-form-item prop="username">
          <el-input
            placeholder="请输入用户名"
            prefix-icon="el-icon-user-solid"
            v-model="ruleForm.username"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password" label="">
          <el-input
            show-password
            placeholder="请输入密码"
            prefix-icon="el-icon-s-order"
            v-model="ruleForm.password"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="login-btn" @click="submitForm"
            >登录</el-button
          >

          <el-button type="primary" class="login-btn">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>



<script>
import { login } from "../api/login";

export default {
  data() {
    return {
      //绑定的参数
      ruleForm: {
        username: "",
        password: "",
      },
      //表单的验证
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 5,
            max: 10,
            message: "长度在 5 到 10 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    //点击提交按钮
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          login(this.ruleForm)
            .then((data) => {
              let res = data;
              console.log(res);
              //判断账号密码正确
              if (res.code === 1000) {

                this.$message({ type: "success", message: res.msg });
              } else {
                this.$message({ type: "error", message: res.msg });
              }
            })
            .catch((err) => {
              console.log(err);
              this.$message({ type: "error", message: err });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>


<style lang="less" scoped>
.login-container {
  background-color: #93defe;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;

  .login-left {
    margin-right: 100px;
    .aaa{
      width: 593px;
      height: 421px;
    }
  }

  .login-box {
    width: 400px;
    height: 350px;
    background-color: #fff;
    padding: 50px;
    border-radius: 6px;
    box-sizing: border-box;
    position: relative;

    .avator-box {
      height: 120px;
      width: 120px;
      border: 5px solid pink;
      border-radius: 100px;
      text-align: center;
      line-height: 120px;
      position: absolute;
      top: -50px;
      right: 135px;
      background-color: white;
    }

    .title {
      position: absolute;
      top: 100px;
      left: 50%;
      transform: translate(-50%);
      font: 20px;
      color: black;
    }

    .login-form {
      position: absolute;
      bottom: 0px;
      left: 50%;
      transform: translate(-50%);
      width: 80%;

      .login-btn {
        width: 30%;
        margin-right: 30px;
      }
    }
  }
}
</style>